package kneipe;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;

import kneipe.personen.Gast;
import kneipe.personen.Person;

public class GuestPopup extends JDialog {
	private static final long serialVersionUID = 1L;
	private Person<?> person;

	public GuestPopup() {

	}

	public GuestPopup(Person<?> person) {
		this.setPerson(person);
		JPanel panel = new JPanel();
		this.add(panel);
		JButton kickButton = new JButton("KICK");
		kickButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(getPerson().getSeat()!=null) {
				getPerson().getKneipe().log("["+getPerson().getSeat().getNumber()+"] KICK: "+getPerson().getName());
				}else{
					getPerson().getKneipe().log("[##] KICK: "+getPerson().getName()+" - hat aber bereits das Lokal verlassen.");					
				}
				getPerson().leave();
				close();
			}
		});
		JButton kickButton2 = new JButton("NEUER PLATZ");
		kickButton2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(getPerson().getSeat()!=null) {
					getPerson().getKneipe().log("["+getPerson().getSeat().getNumber()+"] ANDEREN PLATZ SUCHEN: "+getPerson().getName());
				}else{
					getPerson().getKneipe().log("[##] ANDEREN PLATZ SUCHEN: "+getPerson().getName()+" - hat aber bereits das Lokal verlassen.");					
				}
				Gast<?> gast = (Gast<?>)getPerson();
				gast.newSeat();
				close();
			}
		});
		JPanel infoBox = new JPanel();
		infoBox.setLayout(new BoxLayout(infoBox, BoxLayout.PAGE_AXIS));
		infoBox.add(new JLabel("Name: "+getPerson().getName()));
		infoBox.add(new JLabel("Geld: "+getPerson().getMoneyAmount()));
		panel.add(infoBox);
		panel.add(kickButton);
		panel.add(kickButton2);
		this.setLocationRelativeTo(getPerson().getKneipe());
		this.pack();
		this.setVisible(true);
	}

	@Override
	public void repaint() {
		System.out.println("JO");
	}

	public void close() {
		this.dispose();
	}

	public Person<?> getPerson() {
		return person;
	}

	public void setPerson(Person<?> person) {
		this.person = person;
	}

}
